import 'package:enterprise_v6_app/app/components/common/custom_text_widget.dart';
import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/process/approval_bottom_sheet.dart';
import 'package:enterprise_v6_app/app/components/process/closure_approval_process_widget.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/task_closure/common/common_closure_method.dart';
import 'package:enterprise_v6_app/app/modules/task/task_all/task_closure/task_appointment_review/common_approval_details/common_approval_details_controller.dart';

/// 通用审核详情
class CommonApprovalDetailsPage extends StatelessWidget {
  CommonApprovalDetailsPage({super.key});

  final controller = Get.put(CommonApprovalDetailsController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          return Scaffold(
              appBar: CustomAppBar(
                titleText: '审核详情',
              ),
              body: DefaultTabController(
                  length: 2,
                  child: Column(children: [
                    Container(
                      height: 54.w,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(8.r),
                      ),
                      child: TabBar(
                        tabs: const [
                          Tab(text: '基本信息'),
                          Tab(text: '审批流程'),
                        ],
                        dividerColor: Colors.transparent,
                        labelPadding: EdgeInsets.only(bottom: 20.w),
                        labelStyle: TextStyle(
                          fontSize: 16.sp,
                          fontWeight: FontWeight.w500,
                        ),
                        unselectedLabelStyle: TextStyle(
                          fontSize: 16.sp,
                          fontWeight: FontWeight.w500,
                        ),
                        labelColor: Colors.black,
                        unselectedLabelColor: const Color(0xffA0A7B5),
                        indicatorPadding: EdgeInsets.only(top: 35.w, bottom: 10.w),
                        indicator: const BoxDecoration(
                          image: DecorationImage(
                            image: AssetImage(
                              AppImages.icon_app_work_plan,
                            ),
                          ),
                        ),
                      ),
                    ),
                    Expanded(
                      child: TabBarView(
                        children: [
                          // 基本信息
                          _getBasicInfo(),
                          // 审批流程
                          Column(
                            children: [
                              Container(
                                height: 38.w,
                                width: double.infinity,
                                color: AppColors.bg_color_grey,
                                alignment: Alignment.centerLeft,
                                padding: EdgeInsets.only(left: 16.w),
                                child: Text(
                                  '审批流程',
                                  style: TextStyle(
                                    fontSize: 12.sp,
                                    color: AppColors.text_grey,
                                  ),
                                ),
                              ),
                              Container(
                                height: 2.w,
                                color: AppColors.blue_button,
                              ),
                              Expanded(child: ClosureApprovalProcessWidget(nodeList: controller.nodeList, isReject: controller.item.appointmentStatus == 2)),
                            ],
                          ),
                        ],
                      ),
                    ),
                    SizedBox(height: 230.w)
                  ])),
              bottomSheet: Visibility(
                visible: !controller.isDetails,
                child: ApprovalBottomSheet(
                    onOpinion: controller.onOpinion,
                    onSign: controller.onSign,
                    onOperation: controller.onOperation),
              ));
        });
  }

  /// 获取基本信息
  Widget _getBasicInfo() {
    return Column(
      children: [
        Container(
          height: 38.w,
          width: double.infinity,
          color: AppColors.bg_color_grey,
          alignment: Alignment.centerLeft,
          padding: EdgeInsets.only(left: 16.w),
          child: Text(
            '基本信息',
            style: TextStyle(
              fontSize: 12.sp,
              color: AppColors.text_grey,
            ),
          ),
        ),
        Container(
          height: 2.w,
          color: AppColors.blue_button,
        ),
        _getTitleView(),
        Container(
          height: 1.w,
          color: AppColors.divider_color_blue,
        ),
        Expanded(
            child: SingleChildScrollView(
          child: Container(
              alignment: Alignment.topCenter,
              color: const Color(0xffffffff),
              padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 16.w),
              child: _getContentView()),
        )),
      ],
    );
  }

  /// 获取标题显示
  Widget _getTitleView() {
    return Container(
      height: 64.w,
      color: const Color(0xFFF4F7FF),
      child: Row(
        children: [
          AppGaps.hGap30,
          Visibility(
            visible: controller.type == 0,
            child: Row(
              children: [
                ClipRRect(
                    borderRadius: BorderRadius.circular(4),
                    child: controller.item.photoUrl.isNotEmpty
                        ? Image.network(
                            Interface.fileUrl + controller.item.photoUrl,
                            width: 45.w,
                            height: 45.w,
                            fit: BoxFit.cover,
                          )
                        : Container(
                            color: Colors.white,
                            width: 45.w,
                            height: 45.w,
                          )),
                AppGaps.hGap20,
              ],
            ),
          ),
          Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                '${controller.type == 0 ? '人员姓名' : '驾驶员姓名'}：${controller.item.name}',
                style: TextStyle(
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w500,
                ),
              ),
              AppGaps.vGap4,
              Text(
                '联系方式: ${controller.item.visitorTelephone}',
                style: TextStyle(
                  fontSize: 13.sp,
                  color: const Color(0xFF3F425B),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  /// 获取内容显示
  Widget _getContentView() {
    switch (controller.type) {
      case 0:
        return _getPersonnelInfoView();
      case 1:
        return _getOrdinaryVehiclesInfoView();
      case 2:
        return _getDangerVehiclesInfoView();
      default:
        return Container();
    }
  }

  /// 获取人员信息显示
  Widget _getPersonnelInfoView() {
    return Column(
      children: [
        CustomTextWidget.getTextRowView(title: '人员类型：', value: CommonClosureMethod.getPersonTypeValue(controller.item.type)),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '性别：', value: controller.item.sex == 0 ? '男' : (controller.item.sex == 1 ? '女' : '保密')),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '所属单位：', value: controller.item.affiliatedUnit),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '对接人：', value: controller.item.contactPerson),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '对接人电话：', value: controller.item.personToPersonPhoneNumber),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '预计到访时间：', value: controller.item.startDate),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '来访事由：', value: controller.item.reasonForVisit),
      ],
    );
  }

  /// 获取普通车辆信息显示
  Widget _getOrdinaryVehiclesInfoView() {
    return Column(
      children: [
        CustomTextWidget.getTextRowView(title: '证件号码：', value: controller.item.idNo),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '车辆号码：', value: controller.item.licensePlate),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '车辆类型：', value: CommonClosureMethod.getCarTypeValue(controller.item.carType)),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '所属企业：', value: controller.item.affiliatedUnit),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '对接人：', value: controller.item.contactPerson),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '对接人电话：', value: controller.item.personToPersonPhoneNumber),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '预计到访时间：', value: controller.item.startDate),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '来访事由：', value: controller.item.reasonForVisit),
      ],
    );
  }

  /// 获取危化车辆信息显示
  Widget _getDangerVehiclesInfoView() {
    return Column(
      children: [
        CustomTextWidget.getTextRowView(title: '证件号码：', value: controller.item.idNo),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '车牌号码：', value: controller.item.licensePlate),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '运输介质：', value: controller.item.transportMedium),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '车辆状态：', value: controller.item.carStatus == '1' ? '重载' : '空载'),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '所属运输企业：', value: controller.item.affiliatedUnit),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '押运员姓名：', value: controller.item.nameOfEscort),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '对接人：', value: controller.item.contactPerson),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '对接人电话：', value: controller.item.personToPersonPhoneNumber),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '预计到访时间：', value: controller.item.startDate),
        AppGaps.vGap16,
        CustomTextWidget.getTextRowView(title: '来访事由：', value: controller.item.reasonForVisit),
      ],
    );
  }
}
